package com.dj.uphome.web.shiro;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.alibaba.fastjson.JSONObject;
import com.dj.common.web.service.ValueObject;
import com.dj.common.web.vo.UserVo;
import com.dj.uphome.web.util.Const;

public final class ShiroUtil {
	private ShiroUtil() {
		throw new RuntimeException();
	}

	public static HttpServletRequest getRequest() {
		return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
	}
	public static Session getSession() {
		return  SecurityUtils.getSubject().getSession();
	}
	public static JSONObject getLoginUser() {
		return (JSONObject) SecurityUtils.getSubject().getSession().getAttribute(Const.SESSION_USER);
	}
	public static long getUserId() {
		JSONObject vo =  (JSONObject) SecurityUtils.getSubject().getSession().getAttribute(Const.SESSION_USER);
		if(null!=vo){
			return vo.getLongValue("userId");
		}
		return 0;
	}
	public static String getUserName() {
		JSONObject vo =  (JSONObject) SecurityUtils.getSubject().getSession().getAttribute(Const.SESSION_USER);
		if(null!=vo){
			return vo.getString("userName");
		}
		return null;
	}
}
